package com.qianxun.module.application.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxun.framework.web.error.ServiceInterruptionException;
import com.qianxun.module.application.entity.ApplicationDataRelation;
import com.qianxun.module.application.mapper.ApplicationDataRelationMapper;
import com.qianxun.module.application.service.ApplicationDataRelationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 应用关联数据业务处理类
 *
 * @author Admin
 */
@Transactional(rollbackFor = ServiceInterruptionException.class)
@Service
public class ApplicationDataRelationServiceImpl implements ApplicationDataRelationService {
    @Resource
    private ApplicationDataRelationMapper baseMapper;

    /////////////////////////////////分表逻辑begin//////////////////////

    @Override
    public int createTable(String tableName) {
        return this.baseMapper.createTable(tableName);
    }

    @Override
    public int queryCount(String tableName, String appId, String dataType) {
        return this.baseMapper.queryCount(tableName, appId, dataType);
    }

    @Override
    public int insertIntoTable(String tableName, String appId, String dataType,
                               String dataKey, Date createdTime,
                               String sort1, String sort2, String sort3, String sort4, String sort5
    ) {
        return this.baseMapper.insertIntoTable(tableName, appId, dataType, dataKey, createdTime, sort1, sort2, sort3, sort4, sort5);
    }

    @Override
    public int deleteData(String tableName, String appId, String dataType) {
        return this.baseMapper.deleteData(tableName, appId, dataType);
    }

    @Override
    public int copyData(String targetTableName, String originTableName, String appId, String dataType) {
        return this.baseMapper.copyData(targetTableName, originTableName, appId, dataType);
    }

    /////////////////////////////////分表逻辑end//////////////////////

    /////////////////////////////////查询逻辑begin/////////////////////

    @Override
    public List<ApplicationDataRelation> selectByPage(List<String> tables, String appId, String dataType, String dataKey, Set<Map<String, String>> sortList, Page<ApplicationDataRelation> page) {
        List<ApplicationDataRelation> dataRelations = this.baseMapper.selectByPage(tables, appId, dataType, dataKey, sortList, page);
        return dataRelations;
    }

    /////////////////////////////////查询逻辑end//////////////////////
}
